# -*- coding: utf-8 -*- 
'''
Created on 2 sept. 2012

@author: Cybil
'''
from Window.MainGUI import MainGUI
import wx
from Data.Controller import Controller
from Data.TchatPlayer import TchatPlayer

class MainGUIManager(MainGUI):
    '''
    GUI of the Main Frame
    '''
    def __init__(self, parent):
        '''
        Constructor
        '''
        MainGUI.__init__(self, parent)
        self.__mController = None

        
    def SetController(self, inController):
        self.__mController = inController
        self._mGameDrawPanel.SetController(inController)
        
    def OnConectButtonClick(self, event):
        theIp = self._mIpTextCtrl.GetValue()
        thePort = int(self._mPortTextCtrl.GetValue())
        theName = self._mNickNameTextCtrl.GetValue()
        self.__mController.ConnectServeur(theIp,thePort,theName)
        self._mHostButton.Enable(False)
        self._mConnectionButton.Enable(False)
    
    def UpdateListPlayer(self):
        self._mPlayerListBox.Clear()
        for theElt in self.__mController.GetPlayerList():
            self._mPlayerListBox.Append(str(theElt.GetName()), theElt)
            
    def OnSendMsgButtonClick(self, event):
        self.OnSendMsgTextEnter(event)
    
    def OnSendMsgTextEnter(self, event):
        theMsg = self._mSendMsgTextCtrl.GetValue()
        self._mSendMsgTextCtrl.SetValue('')
        thePlayer = self.__mController.GetPlayer()
        theTchatPlayer = TchatPlayer(theMsg, thePlayer)
        self.__mController.SendObject(theTchatPlayer)
    
    def OnReadyButtonClick(self, event):
        #add exception
        pass

    def AddClickPlayer(self, inClickPlayer):
        self._mGameDrawPanel.AddClickPlayer(inClickPlayer)
        
    def AddMovePlayer(self, inMovePlayer):
        self._mGameDrawPanel.AddMovePlayer(inMovePlayer)
        
    def OnHostButtonClick(self, event):
        #add exception
        theIp = self._mIpTextCtrl.GetValue()
        thePort = int(self._mPortTextCtrl.GetValue())
        theName = self._mNickNameTextCtrl.GetValue()
        self.__mController.HostServeur(theIp,thePort,theName)
        self._mHostButton.Enable(False)
        self._mConnectionButton.Enable(False)
   
    def WriteTchatPlayer(self, inTchatPlayer):
        self._mTchatBox.AppendText(str(inTchatPlayer))
        
    def UpdateScore(self):
        self._mGameDrawPanel.UpdateScore()
    
    def __del__(self):
        pass

if __name__ == "__main__":
    app = wx.App(0)
    theWindows = MainGUIManager(None)
    theController = Controller(theWindows)
    theWindows.Show(True)
    app.MainLoop()     
        